program xyz2copa;
uses common,inp,outp,tools,decor,ppot;
Var
   i,j,k,o,nxyz,tinp : integer;
   tname,xyzname     : mystring;
   txt		     : text;
   chx		     : array[1..nsites] of integer;
   rax		     : array[1..nsites] of v3;
   r		     : v3;
   eps,cmp,tmp	     : myreal;
BEGIN
   export_occup:=true;
   readln(xyzname);
   readln(tname);
   readln(eps);
   {writeln('TILING ',tname);}
   {writeln('XYZfile ',xyzname);}
   write('registering: tol=',eps:1:5);
   reset(txt,'INPUT/objects.def');
   readln(txt,deconame);
   readln(txt,i,o,j);
   if (j=1) then repre5:=true else repre5:=false;
   readln(txt,dpmodel);
   close(txt);
   BASIS;
   reset(txt,tname);
   IMPORT_TILING_BODY(tinp,txt);
   close(txt);
   {writeln('mark1');}
   TABLE_INIT;
   {writeln('mark2');}
   UNIT_CELL(multi);
   {writeln('mark3');}
   i:=0;
   READ_DECO(i); {reads objects.def, ap.def}
   {writeln('mark4');}
   reset(txt,xyzname);
   for i:=1 to 3 do readln(txt); {basis}
   readln(txt,nxyz);
   for i:=1 to nxyz do begin
      for o:=1 to 3 do read(txt,rax[i,o]); readln(txt,chx[i]);
   end;
   close(txt);
   writeln(' -> ',nxyz:1,' atoms');
   for i:=1 to tnodes do nan[i]:=0;
   for i:=1 to tnodes do NEW_NODE_OBJECTS(i,1);
   for i:=1 to tnodes do begin
      for j:=1 to nan[i] do begin
	 for o:=1 to 3 do r[o]:=bound(n_r[i,j,o]+rt[i,o]);
	 n_a[i,j,1]:=0;
	 {write(i:1,' ',j:1,' ');}
	 {for o:=1 to 3 do write(r[o]:1:4,' ');}
	 {writeln;}
	 cmp:=0.0;
	 for k:=1 to nxyz do if (chx[k]>0) then begin
	    tmp:=dist3(r,rax[k]);
	    if (tmp<eps) then begin
	       {writeln('REGISTERING ',k:1,'(',chx[k]:1,') ->',i:1,'/',j:1);}
	       n_a[i,j,1]:=chx[k];
	       chx[k]:=0;
	    end;
	 end;
      end;
   end;
   export_config('copa.upd');
END.


